package com.shop.loan.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shop.loan.channel.lihuo.LiHuoSignUtil;
import com.shop.loan.mapper.*;
import com.shop.loan.model.common.Code;
import com.shop.loan.model.common.ResResult;
import com.shop.loan.model.common.ResResultByCiWei;
import com.shop.loan.model.common.ResResultByLiHuo;
import com.shop.loan.model.entity.*;
import com.shop.loan.model.enums.ChannelType;
import com.shop.loan.model.enums.OrderStatus;
import com.shop.loan.model.enums.PlatformType;
import com.shop.loan.model.enums.UserStatus;
import com.shop.loan.model.vo.ARParamVo;
import com.shop.loan.model.vo.LoanOrderVo;
import com.shop.loan.redis.RedisCache;
import com.shop.loan.redis.RedisLockUtil;
import com.shop.loan.redis.RedisUtil;
import com.shop.loan.service.*;
import com.shop.loan.util.Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class LiHuoServiceImpl implements LiHuoService {

    @Value("${api.lihuo.productCode}")
    private String productCode;

    @Value("${api.lihuo.productSecret}")
    private String productSecret;

    @Resource
    ContractByMybatisMapper contractByMybatisMapper;

    @Value("${api.qiniu.fileDomainByQn}")
    private String fileDomainByQn;


    @Value("${api.lihuo.notifyUrl}")
    private String notifyUrl;

    @Value("${sys.urlByH5}")
    private String urlByH5;

    @Value("${api.lihuo.channelId}")
    private Long channelId;

    @Resource
    RedisUtil redisUtil;

    @Resource
    RedisLockUtil redisLockUtil;

    @Resource
    UserByMybatisMapper userByMybatisMapper;

    @Resource
    LoanOrderByMybatisMapper loanOrderByMybatisMapper;

    @Resource
    UserAuthLogByMybatisMapper userAuthLogByMybatisMapper;

    @Resource
    UserContactByMybatisMapper userContactByMybatisMapper;

    @Resource
    UserLoginLogByMybatisMapper userLoginLogByMybatisMapper;

    @Resource
    LoanOrderService loanOrderService;

    @Resource
    LoanOrderBillByMybatisMapper loanOrderBillByMybatisMapper;

    @Resource
    ArNotifyLogMybatisMapper arNotifyLogMybatisMapper;

    @Resource
    AsyncService asyncService;

    @Resource
    ProductByMybatisMapper productByMybatisMapper;

    @Resource
    UserService userService;

    @Resource
    UserBankByMybatisMapper userBankByMybatisMapper;

    @Resource
    PayOrderThirdByMybatisMapper payOrderThirdByMybatisMapper;

    @Resource
    LoanOrderAuthByMybatisMapper loanOrderAuthByMybatisMapper;

    @Override
    public ResResultByLiHuo contractQuery(Map<String, String> requestBody) {
        if (!LiHuoSignUtil.verifySignature(requestBody, productSecret)) {
            log.info("离火 验签失败");
            return new ResResultByLiHuo(Code.SIGN_ERROR);
        }
        JSONArray backArray = new JSONArray();
        String redisValue = redisUtil.get(RedisCache.arContract);
        if (JSON.isValidArray(redisValue)) {
            return new ResResultByLiHuo(Code.SUCCESS, JSON.parseArray(redisValue));
        }
        ContractByMybatis contractByMybatis = new ContractByMybatis();
        contractByMybatis.setAppShow(true);
        contractByMybatis.setStatus(true);
        List<ContractByMybatis> contractByMybatisList = contractByMybatisMapper.selectByList(contractByMybatis);
        if (contractByMybatisList != null && contractByMybatisList.size() > 0) {
            for (ContractByMybatis byMybatis : contractByMybatisList) {
                JSONObject item = new JSONObject();
                item.put("contractName", byMybatis.getName());
                item.put("contractUrl", fileDomainByQn + byMybatis.getDetailByEmpty());

                backArray.add(item);
            }
            redisUtil.set(RedisCache.arContract, backArray.toJSONString());
        }
        return new ResResultByLiHuo(Code.SUCCESS, backArray);
    }

    @Override
    public ResResultByLiHuo checkUser(Map<String, String> requestBody) {
        JSONObject dataJs = new JSONObject();
        dataJs.put("amount", "0");
        dataJs.put("msg", "");
        if (!LiHuoSignUtil.verifySignature(requestBody, productSecret)) {
            log.info("离火 验签失败");
            return new ResResultByLiHuo(Code.SIGN_ERROR);
        }
        String phoneMd5 = requestBody.get("phoneMd5");
        String idMd5 = requestBody.get("idMd5");
        UserByMybatis userByMybatis = userByMybatisMapper.selectMobileIdcardByMd5(phoneMd5, idMd5);
        if (userByMybatis != null && userByMybatis.getId() != null) {
            if (userByMybatis.getChannelId() != null && userByMybatis.getChannelId() != channelId.longValue()) {
                dataJs.put("status", "106");
                return new ResResultByLiHuo(Code.SUCCESS, dataJs);
            }
            if (!userByMybatis.getMachineStatus()) {
                dataJs.put("status", "105");
                dataJs.put("msg", "风控拒绝");
                return new ResResultByLiHuo(Code.SUCCESS, dataJs);
            }
            LoanOrderByMybatis loanOrderByMybatis = loanOrderByMybatisMapper.selectOrderByIng(userByMybatis.getId());
            if (loanOrderByMybatis != null && loanOrderByMybatis.getId() != null && !loanOrderByMybatis.getOverdueStatus()) {
                dataJs.put("status", "103");
                dataJs.put("msg", "订单逾期");
                return new ResResultByLiHuo(Code.SUCCESS, dataJs);
            }
            if (loanOrderByMybatis != null && loanOrderByMybatis.getId() != null) {
                dataJs.put("status", "102");
                dataJs.put("msg", "有进行中的订单");
                return new ResResultByLiHuo(Code.SUCCESS, dataJs);
            }
        }
//        ProductByMybatis productByMybatis = productByMybatisMapper.selectChannelByOne(channelId);
//        if (productByMybatis != null) {
//            dataJs.put("amount", productByMybatis.getMoney() + "");
//        }
        dataJs.put("status", "000");
        return new ResResultByLiHuo(Code.SUCCESS, dataJs);
    }

    @Override
    public ResResultByLiHuo apply(Map<String, String> requestBody) {
        if (!LiHuoSignUtil.verifySignature(requestBody, productSecret)) {
            log.info("离火 验签失败");
            return new ResResultByLiHuo(Code.SIGN_ERROR);
        }
        ARParamVo arParamVo = JSON.parseObject(JSON.toJSONString(requestBody), ARParamVo.class);
        UserByMybatis userByMybatis = userByMybatisMapper.selectByMobile(arParamVo.getUserPhone());
        if (userByMybatis == null || userByMybatis.getId() == null) {
            //1、插入用户信息
            UserByMybatis user = new UserByMybatis();
            user.setIdentityAuthStatus(true);
            user.setContactAuthStatus(true);
            user.setBankAuthStatus(false);
            user.setMobile(arParamVo.getUserPhone());
            user.setMachineStatus(true);
            user.setUserStatus(UserStatus.normal.getType());
            user.setCreateOrder(false);
            user.setOrderEndNum(0);
            if ("男性".trim().equals(arParamVo.getGender())) {
                user.setGender(1);
            } else {
                user.setGender(2);
            }
            user.setAge(IdcardUtil.getAgeByIdCard(arParamVo.getIdNo()));
            user.setIsDelete(false);
            user.setCreateTime(new Date());
            user.setName(arParamVo.getName());
            user.setChannelId(channelId);
            user.setRegisterIp(arParamVo.getCreateIp());
            user.setCardAddress(arParamVo.getIdCardAddress());
            user.setCardName(arParamVo.getName());
            user.setCardNum(arParamVo.getIdNo());
            user.setIdCardPicFront(arParamVo.getIdCardImgHeadFace());
            user.setIdCardPicBack(arParamVo.getIdCardImgNational());
            redisUtil.hset(RedisCache.registerMobileMap, arParamVo.getUserPhone(), "1");
            userByMybatisMapper.insertSelective(user);

            //2、插入认证记录
            UserAuthLogByMybatis userAuthLogByMybatis = new UserAuthLogByMybatis();
            userAuthLogByMybatis.setUserId(user.getId());
            userAuthLogByMybatis.setIdCardPicBack(arParamVo.getIdCardImgNational());
            userAuthLogByMybatis.setIdCardPicFront(arParamVo.getIdCardImgHeadFace());
            userAuthLogByMybatis.setCardName(arParamVo.getName());
            userAuthLogByMybatis.setCardNum(arParamVo.getIdNo());
//        {"validity":{"birthday":true,"number":true,"address":true,"sex":true,"name":true},"info":{"number":"352203199210236314","address":"福建省福鼎市水北村路外16号","month":"10","nation":"回","year":"1992","sex":"男","name":"丁迪朝","day":"23"}}
            JSONObject OcrInfoByFrontJs = new JSONObject();
            OcrInfoByFrontJs.put("validity", new JSONObject());
            JSONObject OcrInfoByFrontInfo = new JSONObject();
            OcrInfoByFrontInfo.put("number", arParamVo.getIdNo());
            OcrInfoByFrontInfo.put("address", arParamVo.getIdCardAddress());
            OcrInfoByFrontInfo.put("name", arParamVo.getName());
            OcrInfoByFrontJs.put("info", OcrInfoByFrontInfo);
            userAuthLogByMybatis.setOcrInfoByFront(OcrInfoByFrontJs.toJSONString());
//        {"validity":{"authority":true,"timelimit":true},"info":{"authority":"福鼎市公安局","timelimit":"20200915-20400915"}}
            JSONObject OcrInfoByBackJs = new JSONObject();
            OcrInfoByBackJs.put("validity", new JSONObject());
            JSONObject OcrInfoByBackInfo = new JSONObject();
            OcrInfoByBackInfo.put("authority", arParamVo.getSignOrg());
            OcrInfoByBackInfo.put("timelimit", arParamVo.getTermDate());
            OcrInfoByBackJs.put("info", OcrInfoByBackInfo);
            userAuthLogByMybatis.setOcrInfoByBack(OcrInfoByBackJs.toJSONString());
            userAuthLogByMybatis.setAuthUrl(ChannelType.lihuo.getType());
            userAuthLogByMybatis.setAuthFlowId(ChannelType.lihuo.getType() + user.getId() + System.currentTimeMillis());
            userAuthLogByMybatis.setCreateTime(new Date());
            userAuthLogByMybatis.setIdCardAddress(arParamVo.getIdCardAddress());
            userAuthLogByMybatis.setFacePhoto(arParamVo.getFaceImg());
            userAuthLogByMybatisMapper.insertSelective(userAuthLogByMybatis);

            //3、插入紧急联系人
            if (StringUtils.hasLength(arParamVo.getRelations())) {
                JSONArray relations = JSON.parseArray(arParamVo.getRelations());
                for (Object relation : relations) {
                    JSONObject item = JSON.parseObject(JSON.toJSONString(relation));
                    if (item.containsKey("name") && item.containsKey("phone") && item.containsKey("relation")) {
                        UserContactByMybatis userContactByMybatis1 = new UserContactByMybatis();
                        userContactByMybatis1.setName(item.getString("name"));
                        userContactByMybatis1.setMobile(item.getString("phone"));
                        userContactByMybatis1.setRelation(getRelationByStr(item.getString("relation")));
                        userContactByMybatis1.setCreateTime(new Date());
                        userContactByMybatis1.setUserId(user.getId());
                        userContactByMybatisMapper.insertSelective(userContactByMybatis1);
                    }
                }
            }
            userByMybatis = user;
        }
        //获取历史绑卡列表
        Long bankId = null;
        List<UserBankByMybatis> userBankByMybatisList = userBankByMybatisMapper.selectByUser(userByMybatis.getId());
        if (userBankByMybatisList != null && userBankByMybatisList.size() > 0) {
            bankId = userBankByMybatisList.get(0).getId();
        }

        //4、插入登录记录
        UserLoginLogByMybatis userLoginLogByMybatis = new UserLoginLogByMybatis();
        userLoginLogByMybatis.setDeviceInfo(arParamVo.getDeviceBrand());
        userLoginLogByMybatis.setDeviceId(arParamVo.getGuestId());
        userLoginLogByMybatis.setUserId(userByMybatis.getId());
        userLoginLogByMybatis.setCreateTime(new Date());
        userLoginLogByMybatis.setIp(arParamVo.getApplyIp());
        userLoginLogByMybatis.setPlatform(ChannelType.lihuo.getType() + getPlatForm(arParamVo.getClientType()));
        userLoginLogByMybatisMapper.insertSelective(userLoginLogByMybatis);

//        ProductByMybatis productByMybatis = productByMybatisMapper.selectChannelByOne(channelId);

        //生成订单
        LoanOrderVo loanOrderVo = new LoanOrderVo();
//        loanOrderVo.setProductId(productByMybatis.getId());
        loanOrderVo.setReasonType(3);
        loanOrderVo.setBankId(bankId);
        loanOrderVo.setApplyNo(arParamVo.getApplyNo());
        loanOrderVo.setOpId(userByMybatis.getId());
        loanOrderVo.setOpIp(arParamVo.getApplyIp());
        loanOrderVo.setPFrom(getPlatForm(arParamVo.getClientType()));
        ResResult resResult = loanOrderService.create(loanOrderVo, true);
        if (resResult.getCode() == Code.SUCCESS.getCode().intValue()) {
            JSONObject backJs = new JSONObject();
            backJs.put("tradeNo", resResult.getData());
//            backJs.put("borrowTotalCapital", productByMybatis.getMoney());
            return new ResResultByLiHuo(Code.SUCCESS, backJs);
        } else {
            return new ResResultByLiHuo(resResult);
        }
    }

    private Integer getRelationByStr(String relation) {
        if (!StringUtils.hasLength(relation)) {
            return 1;
        }
        if ("父亲".trim().equals(relation)) {
            return 1;
        } else if ("母亲".trim().equals(relation)) {
            return 1;
        } else if ("配偶".trim().equals(relation)) {
            return 5;
        } else if ("子女".trim().equals(relation)) {
            return 2;
        } else if ("朋友".trim().equals(relation)) {
            return 4;
        } else if ("同事".trim().equals(relation)) {
            return 8;
        } else if ("同学".trim().equals(relation)) {
            return 7;
        }
        return 9;
    }

    private String getPlatForm(String clientType) {
        if (!StringUtils.hasLength(clientType)) {
            return PlatformType.h5.getType();
        }
        if ("iphone".trim().equals(clientType) || "android".trim().equals(clientType)) {
            return PlatformType.app.getType();
        }
        return PlatformType.h5.getType();
    }


    @Override
    public ResResultByLiHuo getUrl(Map<String, String> requestBody) {
        if (!LiHuoSignUtil.verifySignature(requestBody, productSecret)) {
            log.info("离火 验签失败");
            return new ResResultByLiHuo(Code.SIGN_ERROR);
        }
        String urlType = requestBody.get("urlType");
        String applyNo = requestBody.get("applyNo");
        UserByMybatis userByMybatis = userByMybatisMapper.selectByApplyNo(applyNo);
        if (userByMybatis == null || userByMybatis.getChannelId() == null || userByMybatis.getChannelId() != channelId.intValue()) {
            return new ResResultByLiHuo(Code.PARAM_INVALID);
        }
        ResResultByCiWei resResult = userService.loginByCiWei(userByMybatis.getMobile(), channelId, ChannelType.lihuo.getType(), null);
        if ("tixian".trim().equals(urlType)) {
            JSONObject dataJs = new JSONObject();
            dataJs.put("url", urlByH5 + "pagesIndex/card/add?token=" + resResult.getData());
            return new ResResultByLiHuo(Code.SUCCESS, dataJs);
        } else if ("huankuan".trim().equals(urlType)) {
            LoanOrderByMybatis loanOrderByMybatis = loanOrderByMybatisMapper.selectOrderByOtherApplyNo(applyNo);
            JSONObject dataJs = new JSONObject();
            dataJs.put("url", urlByH5 + "pagesIndex/log/borrowdetails?token=" + resResult.getData() + "&orderId=" + loanOrderByMybatis.getId());
            return new ResResultByLiHuo(Code.SUCCESS, dataJs);
        }
        return new ResResultByLiHuo(Code.PARAM_INVALID);
    }


    @Override
    public ResResultByLiHuo notifyOrderStatus(LoanOrderByMybatis loanOrderByMybatis, UserByMybatis userByMybatis) {
        List<LoanOrderBillByMybatis> billByMybatisList = loanOrderBillByMybatisMapper.selectListByOrder(loanOrderByMybatis.getId());

        Integer payNum = 0;
        Integer period = null;
        String payTime = null;
        Long lastPayTime = null;
        BigDecimal unPayPeriodMoney = BigDecimal.ZERO;
        for (LoanOrderBillByMybatis loanOrderBillByMybatis : billByMybatisList) {
            if (loanOrderBillByMybatis.getPayStatus()) {
                payNum++;
                lastPayTime = loanOrderBillByMybatis.getOpTime().getTime();
            } else {
                if (payTime == null) {
                    unPayPeriodMoney = Util.getUnPayMoney(loanOrderBillByMybatis);
                    period = loanOrderBillByMybatis.getPeriod();
                    payTime = DateUtil.formatDate(loanOrderBillByMybatis.getPayTime());
                }
            }
        }
        Long loanPassDate = null, receivedDate = null;
        //放款成功时间
        if (loanOrderByMybatis.getStatus() == OrderStatus.underway.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.end.getStatus().intValue()) {
            PayOrderThirdByMybatis payOrderThirdByMybatis = payOrderThirdByMybatisMapper.selectLastLoanStatus(loanOrderByMybatis.getId());
            if (payOrderThirdByMybatis != null && payOrderThirdByMybatis.getSuccessTime() != null) {
                receivedDate = payOrderThirdByMybatis.getSuccessTime().getTime();
            }
        }
        //审核通过时间
        if (loanOrderByMybatis.getStatus() == OrderStatus.wait_loan.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.underway.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.end.getStatus().intValue()) {
            LoanOrderAuthByMybatis loanOrderAuthByMybatis = loanOrderAuthByMybatisMapper.selectFirstPassByOrder(loanOrderByMybatis.getId());
            if (loanOrderAuthByMybatis != null) {
                loanPassDate = loanOrderAuthByMybatis.getCreateTime().getTime();
            }
        }

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("productCode", productCode);
        paramMap.put("applyNo", loanOrderByMybatis.getOtherApplyNo());//我方进件接口传递的订单号
        paramMap.put("tradeNo", loanOrderByMybatis.getId());//合作方进件接口回传的订单号
        paramMap.put("orderStatus", getOrderStatus(loanOrderByMybatis, loanOrderByMybatis.getStatus()));
        paramMap.put("auditStatus", getAuditStatus(loanOrderByMybatis.getStatus()));//审核状态 1审核通过 2审核拒绝
        paramMap.put("payStatus", getPayStatus(loanOrderByMybatis.getStatus())); //放款状态 0初始化 1成功 2 失败
        if (loanOrderByMybatis.getStatus() == OrderStatus.end.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.underway.getStatus().intValue()) {
            paramMap.put("receivedDate", receivedDate); //放款到账时间戳，精确到毫秒（当订单状态为待还款时，此字段必传）
        }
        if (loanOrderByMybatis.getStatus() == OrderStatus.wait_loan.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.underway.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.end.getStatus().intValue()) {
            paramMap.put("loanPassDate", loanPassDate); //审核通过时间戳，精确到毫秒
        }
        paramMap.put("totalPeriod", loanOrderByMybatis.getPeriod()); //总期数
        paramMap.put("paidPeriod", payNum); //已还期数
        paramMap.put("borrowTotalCapital", getMoneyByFen(loanOrderByMybatis.getMoney())); //借款总金额，以分为单位
        paramMap.put("repaymentTotalCapital", getMoneyByFen(loanOrderByMybatis.getMoney().add(loanOrderByMybatis.getRateMoney()).add(loanOrderByMybatis.getShopMoney()))); //应还总金额，以分为单位
        if (loanOrderByMybatis.getStatus() == OrderStatus.wait_loan.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.underway.getStatus().intValue()
                || loanOrderByMybatis.getStatus() == OrderStatus.end.getStatus().intValue()) {
            paramMap.put("currentRepaymentCapital", getMoneyByFen(unPayPeriodMoney)); //当前期应还金额，以分为单位
            paramMap.put("currentPeriod", period); //当前应还期数
            paramMap.put("currentRepaymentDate", payTime); //当前期应还时间，格式为yyyy-MM-dd
        }
        if (loanOrderByMybatis.getStatus() == OrderStatus.end.getStatus().intValue()) {
            paramMap.put("payOffDate", lastPayTime); //还清时间戳，精确到毫秒（当订单状态为已还清时，此字段必传）
        }
        paramMap.put("timestamp", System.currentTimeMillis()); //还当前更新时间戳
        paramMap.put("sign", LiHuoSignUtil.sign(paramMap, productSecret)); //还当前更新时间戳
        //插入推送记录表
        ArNotifyLogMybatisWithBLOBs arNotifyLogMybatis = new ArNotifyLogMybatisWithBLOBs();
        arNotifyLogMybatis.setReqParam(JSON.toJSONString(paramMap));
        arNotifyLogMybatis.setCreateTime(new Date());
        arNotifyLogMybatis.setStatus(false);
        arNotifyLogMybatis.setUrl(notifyUrl);
        arNotifyLogMybatisMapper.insertSelective(arNotifyLogMybatis);

        asyncService.sendNotify(arNotifyLogMybatis, null);
        return new ResResultByLiHuo(Code.SUCCESS);
    }


    @Async
    @Override
    public void taskByNotify() {
        String lockValue = String.valueOf(System.currentTimeMillis());
        String lockKey = RedisCache.arNotifyLock;
        Jedis jedis = redisUtil.getJedis();
        try {
            if (!redisLockUtil.lock(jedis, lockKey, lockValue)) {
                log.info("推送线程正在进行中");
                return;
            }
            boolean run = true;
            while (run) {
                Object orderIdObj = redisUtil.rpop(RedisCache.arNotifyQueue);
                if (orderIdObj == null) {
                    return;
                }
                asyncService.sendNotify(null, Long.parseLong(orderIdObj.toString()));
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(Util.GetErrorDetails(e));
        } finally {
            if (jedis != null) {
                redisLockUtil.release(jedis, lockKey, lockValue);
                jedis.close();
            }
        }
    }


    public Integer getOrderStatus(LoanOrderByMybatis loanOrderByMybatis, Integer orderStatus) {
        if (orderStatus == OrderStatus.refuse.getStatus().intValue()) {
            return 21;
        } else if (orderStatus == OrderStatus.refuse_loan.getStatus().intValue()) {
            return 32;
        }

        if (orderStatus == OrderStatus.wait_auth.getStatus().intValue()) {
            return 20;
        }

        if (loanOrderByMybatis.getBankId() == null) {
            return 22;
        }

        if (orderStatus == OrderStatus.wait_loan.getStatus().intValue()) {
            return 30;
        } else if (orderStatus == OrderStatus.underway.getStatus().intValue()) {
            if (!loanOrderByMybatis.getOverdueStatus()) {
                return 41;
            }
            return 40;
        } else if (orderStatus == OrderStatus.end.getStatus().intValue()) {
            return 90;
        }
        return 20;
    }


    public Integer getAuditStatus(Integer orderStatus) {
        if (orderStatus == OrderStatus.refuse.getStatus().intValue() || orderStatus == OrderStatus.refuse_loan.getStatus().intValue()) {
            return 2;
        }
        return 1;
    }

    public Integer getPayStatus(Integer orderStatus) {
        if (orderStatus >= OrderStatus.underway.getStatus()) {
            return 1;
        }
        return 0;
    }

    public Long getMoneyByFen(BigDecimal money) {
        if (money == null) {
            return 0L;
        }
        return money.multiply(BigDecimal.valueOf(100)).longValue();
    }


}
